package org.bbd.cumi.util;

import java.util.Properties;

import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;


/**
 * Class ini digunakan untuk memperoleh akses ke ApplicationContext
 * @author nds
 *
 */
public class SpringUtil implements ApplicationContextAware,InitializingBean{
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(SpringUtil.class);

	private static ApplicationContext applicationContext=null; 
	
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringUtil.applicationContext=applicationContext;        
    }
    
    public static ApplicationContext getApplicationContext(){
    	if (applicationContext==null){
    		throw new RuntimeException(SpringUtil.class.getCanonicalName() + " must be registered in Spring ApplicationContext");
    	}
    	return SpringUtil.applicationContext;
    }    	
    
    public static Object getBean(String name){
        return SpringUtil.getApplicationContext().getBean(name);
    }

	public void afterPropertiesSet() throws Exception {
		Properties prop=new Properties();
	}

}
